package cn.starrysky108.simpleerp.pub.controller;

import cn.starrysky108.simpleerp.core.constant.Constants;
import cn.starrysky108.simpleerp.pub.response.EnumListResponse;
import cn.starrysky108.simpleerp.pub.service.EnumService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @author Carl Lee
 */
@RestController
@Api("系统枚举查看")
@RequestMapping("/pub/enum")
public class EnumController {
    private final EnumService enumService;

    @Autowired
    public EnumController(EnumService enumService) {
        this.enumService = enumService;
    }

    @GetMapping("/{className}")
    @ApiOperation("获取系统枚举值")
    public List<EnumListResponse> getEnumList(@PathVariable  String className) throws ClassNotFoundException {
        return enumService.getEnumList(Class.forName(Constants.ENUM_PACKAGE + className));
    }

    @GetMapping("/list")
    @ApiOperation("获取所有系统枚举值")
    public Map<String, List<EnumListResponse>> lisAll() {
        return enumService.listAll();
    }
}
